import axios from './axios'
// 关于唯一性统一采用身份证号
// json-server中，put为全局修改，patch为部分修改，这里采用全局修改

// 关于'/login'的CRUD
// 用户登录账号 -- GET
export function verifyLogin({ rolename, username, password }) {
  return axios.sendRequest({
    url: '/login',
    method: 'get',
    params: {
      rolename: rolename,
      username: username,
      password: password
    }
  })
}
// 创建用户账号 -- POST
export function verifyLogon({ rolename, username, password, createTime }) {
  return axios.sendRequest({
    url: '/login',
    method: 'post',
    data: {
      username: username,
      password: password,
      rolename: rolename,
      createTime: createTime
    }
  })
}
// 修改用户账号 -- PUT
export function updateAccount(id, accountObj) {
  return axios.sendRequest({
    url: '/login' + `/${id}`,
    method: 'put',
    data: accountObj
  })
}
// 分页获取账户 -- GTE
export function getUser({ url, page, limit, like }) {
  return axios.sendRequest({
    url: url,
    method: 'get',
    params: {
      _page: page,
      _limit: limit,
      username_like: like,
    }
  })
}
export function deleteAccount(identify) {
  return axios.sendRequest({
    url: "/login",
    method: "delete",
    params: {
      identify: identify
    }
  })
}

// 关于【'/student'，'/coach'，'/cars'】的CRUD
// 分页获取数据 '/cars' -- GET
export function getCar({ page, limit, like, isUse }) {
  return axios.sendRequest({
    url: "/cars",
    method: 'get',
    params: {
      _page: page,
      _limit: limit,
      carNumber_like: like,
      isUse: isUse
    }
  })
}
// 根据姓名分页获取'/student'，'/coach'信息 / 根据coachID获取学员信息
export function getUserData({ url, page, limit, like, id, coachID, identify }) {
  return axios.sendRequest({
    url: url,
    method: 'get',
    params: {
      _page: page,
      _limit: limit,
      name_like: like,
      id: coachID,
      identify: identify,
      coachID: id
    }
  })
}

export function getCoachInfoByReverseCar(carNumber) {
  return axios.sendRequest({
    url: "/coach",
    method:'get',
    params: {
      reverseCar_like: carNumber
    }
  })
}
// '/student'，'/coach'，'/cars' 添加数据 -- POST
export function addUserData(url, UserObj) {
  return axios.sendRequest({
    url: url,
    method: 'post',
    data: UserObj
  })
}
// '/student'，'/coach'，'/cars' 修改数据 -- PUT
export function updateUserData(url, id, UserObj) {
  return axios.sendRequest({
    url: url + `/${id}`,
    method: 'put',
    data: UserObj
  })
}
// '/student'，'/coach'，'/cars' 根据id删除数据 -- DELETE
export function deleteUserData(url, id) {
  return axios.sendRequest({
    url: url + `/${id}`,
    method: 'delete',
  })
}

// 关于'/timeArrange'的CRUD
// 添加练车时间 -- POST
export function postTimeArrange(obj) {
  return axios.sendRequest({
    url: '/timeArrange',
    method: 'post',
    data: obj
  })
}
// 修改练车时间 -- PUT
export function updateTimeArrange(id, obj) {
  return axios.sendRequest({
    url: `/timeArrange/${id}`,
    method: 'put',
    data: obj
  })
}
// 根据coach的identify获取练车时间安排 -- GET
export function getArrangedTimeByCoachIdentify(identify) {
  return axios.sendRequest({
    url: '/timeArrange',
    method: 'get',
    params: {
      coachIdentify: identify
    }
  })
}

// 关于 '/studentAppoint' 的CRUD
export function postStudentAppoint(obj) {
  return axios.sendRequest({
    url: '/studentAppoint',
    method: 'post',
    data: obj
  })
}
export function getStudentAppoint(identify) {
  return axios.sendRequest({
    url: '/studentAppoint',
    method: 'get',
    params: {
      studentIdentify: identify
    }
  })
}
export function updateStudentAppoint(id, obj) {
  return axios.sendRequest({
    url: `/studentAppoint/${id}`,
    method: 'put',
    data: obj
  })
}
export function deleteStudentAppoint(id) {
  return axios.sendRequest({
    url: '/studentAppoint' + `/${id}`,
    method: 'delete'
  })
}
export function getStudentAppointByCoachID(coachID) {
  return axios.sendRequest({
    url: '/studentAppoint',
    method: 'get',
    params: {
      coachID: coachID
    }
  })
}

// 获取权限
export function getRights() {
  return axios.sendRequest({
    url: "/authority",
    method: 'get'
  })
}

// 角色'/role'
export function getRoles() {
  return axios.sendRequest({
    url: '/role',
    method: 'get'
  })
}